<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

require_once(APPPATH . '/controllers/super_admin' . EXT);
class Board extends Super_admin {

    function __construct() {
        parent::__construct();

        $this->load->model(array(
            'Group_model',
            'User_model',
            'User_group_model',
            'Group_discussion_model'
        ));

        $this->load->helper(array(
            'security',
            'string',
        ));
    }
    /**
     * list_records
     *
     * Load information list
     *
     * @access public
     * @param int
     * @return void
     */
    function the_board($group_id) {
        $access = array('instructor', 'student');
        $this->_is_authorize($access); //check super_admin controller

        $where = array(
            'group_id' => $group_id,
            'user_id' =>   _session('user_id')
        );

        if ( ! $this->User_group_model->exists($where)) redirect('user/index');

        $data['group'] =  $this->Group_model->get_record(array('where' => 'group_id = "'.$group_id.'"'));

        $this->load->view('board/the_board',$data);
    }
    function submit(){
        $group_id = $this->input->post('group_id', TRUE);

        $data = array(
            'group_id' => $group_id,
            'user_id' => _session('user_id'),
            'message' => $this->input->post('message',TRUE),
            'date_posted' => pdate(),
        ); 

        $this->Group_discussion_model->_insert($data);

    }

    /**
     * get_messages
     *
     * Load information list
     *
     * @access public
     * @param int
     * @return void
     */
    function get_messages($group_id) {
        $access = array('instructor','student');
        $this->_is_authorize($access); //check super_admin controller
        
        $where = array(
            'group_id' => $group_id,
            'user_id' =>   _session('user_id')
        );

        if ( ! $this->User_group_model->exists($where)) redirect('user/index');

       $join_user= array(
            'table' => USERS . ' u',
            'condition' => 'u.user_id = gds.user_id',
        );

        $data['group_discussion'] =  $this->Group_discussion_model->get_list(array(
            'where' => 'group_id = "'.$group_id.'"',
            'join' => array($join_user),
            'order_by' => 'group_discussion_id DESC'
        ));

        $this->load->view('board/get_messages',$data);
    }
   
}
/* End of file board.php */
/* Location: ./application/controllers/board.php */
